/**
 * 
 */
package vanhoc.android.medialcool.utils;

import java.util.HashMap;

import vanhoc.android.mediakool.R;
import vanhoc.android.mediakool.SongListenningActivity;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

/**
 * @author SEVEN
 *
 */
public class NotificationUtils{
	private Context _context;
	private NotificationManager notificationManager;
	public static final int NOTIFICATION_ID = 10001;
	
	public NotificationUtils(Context ct, NotificationManager nm) {
		// TODO Auto-generated constructor stub
		this._context = ct;
		notificationManager = nm;
	}
	
	public void toastNotificationForMusicPlay(String songTitle, String artist, HashMap<String, String> intentData,Boolean isPlaying){
		/*Instantiate the Notification:*/
		int icon;
		
		if (isPlaying) {
			icon = R.drawable.play_32_icon;
		}else{
			icon = R.drawable.pause_32_icon;
		}
    	
    	CharSequence tickerText = _context.getResources().getString(R.string.app_name);
    	long when = System.currentTimeMillis();
    	Notification notification = new Notification(icon, tickerText, when);
    	
    	// Hide the notification after its selected
    	notification.flags |= Notification.FLAG_AUTO_CANCEL;
    	
    	//Define the notification's message and PendingIntent:
    	CharSequence contentTitle = songTitle;
    	CharSequence contentText =  artist;
    	
    	Intent notificationIntent = new Intent(this._context, SongListenningActivity.class);
    	notificationIntent.putExtra("PLAYLIST_ID", intentData.get("PLAYLIST_ID"));
    	notificationIntent.putExtra("FIELDNAME", intentData.get("FIELDNAME"));
    	notificationIntent.putExtra("FIELDVALUE", intentData.get("FIELDVALUE"));
    	notificationIntent.putExtra("SONGIDPLAYING", intentData.get("SONGIDPLAYING"));
		
		
    	PendingIntent contentIntent = PendingIntent.getActivity(this._context, 0, notificationIntent, 0);

    	notification.setLatestEventInfo(this._context, contentTitle, contentText, contentIntent);
    	
    	//Pass the Notification to the NotificationManager:
    	notificationManager.notify(NOTIFICATION_ID, notification);
	}
}
